package com.longrise.android.byjk.plugins.tabthird.invoice;

import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.byjk.R;
import com.longrise.common.utils.AppUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/10/25.
 * 开票历史详情adapter
 */

class BillDetailRcvAdapter extends BaseQuickAdapter<EntityBean, BaseViewHolder>{

    private List<EntityBean> mListBeans = new ArrayList<>();

    public BillDetailRcvAdapter() {
        super(R.layout.item_bill_detail_rcv);
    }

    public void refreshData(EntityBean[] beans) {
        mListBeans.clear();
        for (EntityBean bean : beans) {
            mListBeans.add(bean);
        }
        setNewData(mListBeans);
    }

    @Override
    protected void convert(BaseViewHolder helper, EntityBean item) {
        final View convertView = helper.getConvertView();
        final TextView tv_title = helper.getView(R.id.tv_plan_name);
        final RelativeLayout rl_bill_detail = helper.getView(R.id.rl_bill_detail);

        helper.setText(R.id.tv_plan_name,item.getString("planname"))
                .setText(R.id.tv_consume_price,item.getString("feereally"))
                .setText(R.id.tv_create_time,item.getString("createtime"));

        tv_title.post(new Runnable() {
            @Override
            public void run() {
                int lineCount = tv_title.getLineCount();
                ViewGroup.LayoutParams layoutParams = convertView.getLayoutParams();
                if (lineCount == 2) {
                    layoutParams.height = AppUtil.dip2px(99);
                } else {
                    layoutParams.height = AppUtil.dip2px(73);
                }
                convertView.setLayoutParams(layoutParams);
            }
        });
    }
}
